import 'package:baselib/utils/image_util.dart';
import 'package:baselib/widgets/comm_app_bar.dart';
import 'package:baselib/widgets/comm_textfield.dart';
import 'package:baselib/widgets/gradient_card_view.dart';
import 'package:baselib/widgets/gradient_text_widget.dart';
import 'package:baselib/widgets/inkwell_button.dart';
import 'package:baselib/widgets/refresh_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:framelib/widgets/comm_widget_manager.dart';
import 'package:framelib/widgets/main_gradient_button.dart';
import 'package:framelib/widgets/page_widget.dart';
import 'package:get/get.dart';
import 'package:module_business/module_index/viewmodel/room_admins_view_model.dart';
import 'package:module_business/module_index/viewmodel/room_block_list_view_model.dart';
import 'package:module_business/module_index/viewmodel/room_upmic_person_list_view_model.dart';

/**
 * 房间上线的人员列表主页
 */
class RoomUpmicPersonlistPage extends GetWidget<RoomUpmicPersonViewModel> {
  const RoomUpmicPersonlistPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PageWidget.build(builder: (RoomUpmicPersonViewModel model) {
      return PageWidget.PageScaffoldWidget(
        isShowBg: true,
        appBar: CommAppBar(
          backgroundColor: ColorUtil.instance.color_transparent,
          titleStr: StringUtil.instance.Onmic_Person,
          titleTextStyle: TextStyle(
              fontSize: PxUtil.instance.px_18,
              color: ColorUtil.instance.color_white,
              fontWeight: FontWeight.bold),
          actions: [
            InkWellButton(
              onPressed: () => model.save(),
              child: Container(
                padding: EdgeInsets.only(
                  left: PxUtil.instance.px_15,
                  right: PxUtil.instance.px_15,
                ),
                child: ImagesUtil.loadAssetImage(
                    DrawableUtil.instance.icon_room_set_save,
                    width: PxUtil.instance.px_36,
                    fit: BoxFit.fitWidth),
              ),
            )
          ],
        ),
        body: Container(
          width: PxUtil.instance.screenWidth,
          height: PxUtil.instance.screenHeight -
              PxUtil.instance.statusBarHeight -
              PxUtil.instance.appBarHeight,
          padding: EdgeInsets.only(
            left: PxUtil.instance.px_15,
            right: PxUtil.instance.px_15,
          ),
          child: _buildListUi(model),
        ),
      );
    });
  }

  Widget _buildListUi(RoomUpmicPersonViewModel model) {
    return ListView.builder(
        shrinkWrap: true,
        itemCount: model.upmicPersons?.length ?? 0,
        itemBuilder: (BuildContext context, int index) {
          var chatRoomAdmin = model.upmicPersons[index];
          return Container(
            padding: EdgeInsets.only(
              top: PxUtil.instance.px_12,
              bottom: PxUtil.instance.px_12,
            ),
            decoration: BoxDecoration(
                border: Border(
                    bottom: BorderSide(
                        color: ColorUtil.instance.color_879d9d9d,
                        width: PxUtil.instance.px_0d5))),
            child: Row(
              children: [
                CommWidgetManager.buildCicleImagWidget(
                  chatRoomAdmin?.icon ?? '',
                  placeholder: DrawableUtil.instance.icon_default_head,
                  width: PxUtil.instance.px_56,
                  height: PxUtil.instance.px_56,
                  roundRadius: PxUtil.instance.px_28,
                  backgroundColor: ColorUtil.instance.color_f2f2f2,
                  padding: EdgeInsets.only(),
                  margin: EdgeInsets.only(),
                ),
                SizedBox(
                  width: PxUtil.instance.px_16,
                ),
                Expanded(
                    child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      chatRoomAdmin?.nickname ?? '',
                      style: TextStyle(
                          fontWeight: FontWeight.w500,
                          color: ColorUtil.instance.color_white,
                          fontSize: PxUtil.instance.px_15),
                    ),
                    GradientCardView(
                        margin: EdgeInsets.only(top: PxUtil.instance.px_10),
                        padding: EdgeInsets.only(
                          left: PxUtil.instance.px_8,
                          right: PxUtil.instance.px_8,
                          top: PxUtil.instance.px_1,
                          bottom: PxUtil.instance.px_1,
                        ),
                        borderRadius:
                            BorderRadius.circular(PxUtil.instance.px_2),
                        elevation: PxUtil.instance.px_0,
                        child: Text(
                          '${chatRoomAdmin?.signature ?? 0}',
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: ColorUtil.instance.color_white,
                              fontSize: PxUtil.instance.px_13),
                        ))
                  ],
                )),
                InkWellButton(
                  onPressed: ()=>model.oper(index),
                  child:
                  (chatRoomAdmin?.selected??true)?
                  Icon(
                    Icons.remove_circle_outline,
                    color: ColorUtil.instance.color_EF0A6A,
                  ):
                  Icon(
                    Icons.add_circle,
                    color: ColorUtil.instance.color_9929EA,
                  ),
                )
              ],
            ),
          );
        });
  }
}
